﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors.machines {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class ReceptionMachineQueueModeVO extends ReceptionMachineVO {

        public function ReceptionMachineQueueModeVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
        }
        override public function handlePatient(_arg1:ITreatable):void{
            if (_patient){
                _arg1.moveToNextTarget(GameConstants.TYPE_ENTRANCE_AREA);
                dispatch(new InfoEvent(EventConstants.REPORT_PROBLEM, null, ((("There is already Patient " + _arg1.id) + " in the reception and no place for ") + _arg1.id)));
            } else {
                if (_arg1.state == WorldConstants.ILL){
                    _patient = _arg1;
                    _patient.clickHandler = this.onPatientClicked;
                    if (this.isUncuredElder()){
                        _patient.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_EXCLAMATIONMARK});
                    };
                    dispatch(new InfoEvent(EventConstants.TURN_LEFT, _arg1.id));
                    dispatch(new InfoEvent(EventConstants.ON_ARRIVAL_AT_RECEPTION, _arg1.id));
                    dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_PET_ARRIVES_IN_RECEPTION));
                } else {
                    if ((((_arg1.state == WorldConstants.PATIENT)) && ((_arg1.targetType == null)))){
                        dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id, (("Patient " + _arg1.id) + " is already accepted")));
                        dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                    } else {
                        if (_arg1.state == WorldConstants.CURED){
                            dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id, (("Patient " + _arg1.id) + " is already cured")));
                            dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                        } else {
                            if (_arg1.state == WorldConstants.BABY){
                                dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id));
                                dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                            };
                        };
                    };
                };
            };
            dispatch(new Event(EventConstants.UPDATE_MORE_PETS_ARROW));
            if (!this.isUncuredElder()){
                this.onPatientClicked();
            };
        }
        override protected function onPatientClicked():void{
            if (!_isPatientTelling){
                _isPatientTelling = true;
                this.onArrivalOfAvatar();
            } else {
                acceptPatient();
            };
        }
        override protected function onArrivalOfAvatar():void{
            if (!_patient){
                return;
            };
            if (_patient.diseaseName == WorldConstants.DISEASE_OLD){
                acceptPatient();
                dispatch(new Event(EventConstants.SHOW_TREE));
                dispatch(new Event(EventConstants.SHOW_INVENTORY_GEMS));
                dispatch(new Event(EventConstants.HANDLE_NEXT_AVATAR_ACTION));
            } else {
                startReceptionTimer();
            };
        }
        private function isUncuredElder():Boolean{
            return ((((patient.diseaseName == WorldConstants.DISEASE_OLD)) && (!((patient.state == WorldConstants.CURED)))));
        }

    }
}//package net.wooga.pets.models.world.vos.actors.machines 
